package cn.bdqn.t354.mapper;

import cn.bdqn.t354.pojo.SysUser;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface SysUserMapper {
    /**
     * 查询
     * @return
     */
    //等价于<select>
    @Select("SELECT * FROM sys_user WHERE usr_id = #{id}")
    //等价于<resultMap>
    @Results({
            //等价于<result>标签
            @Result(column = "usr_id",property = "usrId",id = true),
            @Result(column = "usr_name",property = "usrName"),
            @Result(column = "usr_password",property = "usrPassword"),
            @Result(column = "usr_role_id",property = "usrRoleId"),
            @Result(column = "usr_flag",property = "usrFlag"),
    })
    public SysUser selectById(Long id);

    @Update("<script>UPDATE sys_user\n" +
            "<set>\n" +
            "<if test=\"usrName!=null and usrName!=''\">\n" +
            "usr_name = #{usrName},\n" +
            "</if>\n" +
            "<if test=\"usrPassword!=null and usrPassword!=''\">\n" +
            "usr_password = #{usrPassword},\n" +
            "</if>\n" +
            "<if test=\"usrRoleId!=null\">\n" +
            "usr_role_id = #{usrRoleId},\n" +
            "</if>\n" +
            "<if test=\"usrFlag!=null\">\n" +
            "usr_flag = #{usrFlag},\n" +
            "</if>\n" +
            "</set>\n" +
            "WHERE usr_id = #{usrId}" +
            "</script>")
    public int update(SysUser sysUser);
}
